home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume16 / log_tcp / part01 next >
Encoding:
Internet Message Format  |  1991-01-10  |  28.4 KB

  1. From: wietse@wzv.win.tue.nl (Wietse Venema)
  2. Newsgroups: comp.sources.misc
  3. Subject: v16i062:  package to monitor tcp/ip connections, Part01/01
  4. Message-ID: <1991Jan9.040140.25217@sparky.IMD.Sterling.COM>
  5. Date: 9 Jan 91 04:01:40 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: c22717fd c273b430 219da244 922d5a46
  8.  
  9. Submitted-by: wietse@wzv.win.tue.nl (Wietse Venema)
  10. Posting-number: Volume 16, Issue 62
  11. Archive-name: log_tcp/part01
  12.  
  13. This package provides a couple of tiny programs that log all requests
  14. to connection-oriented tcp/ip services (examples: FINGER, SYSTAT, FTP,
  15. TELNET, RLOGIN, RSH, EXEC), with optional access control on the basis
  16. of host (or domain) names and service names.
  17.  
  18. The programs are nothing but small front ends. By default, they just
  19. log the remote host name and then invoke the real daemon. The programs
  20. should not require any changes to existing software or configuration
  21. files.
  22.  
  23. Connections are reported through the syslog(3) facility. Each record
  24. contains a time stamp, the remote host name and the name of the service
  25. requested. Such information can be useful to detect break-in attempts
  26. or other undesirable activities, especially when logfile information
  27. from several hosts is merged.
  28.  
  29. The optional access-control facility may be useful when, for whatever
  30. reason, it is not possible to handle access control at a more suitable
  31. level (such as an internet router).
  32.  
  33.     Wietse Venema,
  34.     Eindhoven University of Technology,
  35.     The Netherlands.
  36.  
  37. #! /bin/sh
  38. # This is a shell archive.  Remove anything before this line, then unpack
  39. # it by saving it into a file and typing "sh file".  To overwrite existing
  40. # files, type "sh file -c".  You can also feed this as standard input via
  41. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  42. # will see the following message at the end:
  43. #        "End of shell archive."
  44. # Contents:  README miscd.c tcpd.c fromhost.c hosts_access.c Makefile
  45. #   hosts_access.5 strcasecmp.c BLURB
  46. # Wrapped by wietse@wzv on Sun Jan  6 22:31:41 1991
  47. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  48. if test -f README -a "${1}" != "-c" ; then 
  49.   echo shar: Will not over-write existing file \"README\"
  50. else
  51. echo shar: Extracting \"README\" \(4779 characters\)
  52. sed "s/^X//" >README <<'END_OF_README'
  53. X@(#) README 1.1 91/01/06 22:30:23
  54. X
  55. XGeneral description:
  56. X
  57. XWith this package you can monitor connections to the SYSTAT, FINGER,
  58. XFTP, TELNET, RLOGIN, RSH and EXEC network services.  Connections are
  59. Xlogged through the syslog(3) facility. A requirement is that daemons
  60. Xare started by the inetd program or something similar.
  61. X
  62. XThe programs are tiny front ends that just report the remote host name
  63. Xand then invoke the real network daemon.  In the most common case, no
  64. Xchanges should be required to existing software or to configuration
  65. Xfiles.  Just move the vendor-provided daemons to another place and
  66. Xinstall the front ends into their original places. Installation details
  67. Xare given below.
  68. X
  69. XEarlier versions of the programs were tested with Ultrix >= 2.2, with
  70. XSunOS >= 3.4 and ISC 2.2. The present version is a bit cleaned up, but
  71. Xshould still run without modification on top of most BSD-style TCP/IP
  72. Ximplementations.
  73. X
  74. XOptional feature:
  75. X
  76. XWhen compiled with -DHOSTS_ACCESS, the front-end programs support a
  77. Xsimple form of access control that is based on host (or domain) names
  78. Xand service names.  Wild cards are supported.  If a host requests a
  79. Xservice, and if the (service, host) pair is matched by an entry in the
  80. X/etc/hosts.allow file, access is granted.  Otherwise, if the (service,
  81. Xhost) pair is matched by an entry in the /etc/hosts.deny file, access
  82. Xis denied.  Otherwise, access is granted.  For more details, see the
  83. Xhosts_access(5) manual page. This form of access control may be useful
  84. Xif it can not be implemented at a more suitable level (such as an
  85. Xinternet router).
  86. X
  87. XRelated software:
  88. X
  89. XVersions of rshd and rlogind, hacked to report the remote user name as
  90. Xwell, are available for anon ftp (ftp.win.tue.nl:/pub/logdaemon.tar.Z).
  91. XThose programs have been tested only with SunOS >= 4.0.
  92. X
  93. XAnother way to manage access to tcp/ip services is illustrated by the
  94. Xservers provided with the authutil package (comp.sources.unix volume
  95. X22). This has the advantage that one will get the remote username from
  96. Xany host supporting RFC 931 security.  By installing the auth package
  97. X(same volume) one supports RFC 931 security too.  Eventually one can
  98. Xstart cutting off unauthenticated connections. This is obviously a much
  99. Xmore advanced approach than what my front-end programs provide. The
  100. Xpresent package is more suitable for those who lack the resources to
  101. Xinstall anything that requires more than just renaming a couple of
  102. Xexecutables.
  103. X
  104. XConfiguration and installation:
  105. X
  106. XIf you don't run Ultrix, you don't need the miscd front-end program.
  107. XThe Ultrix miscd daemon implements among others the SYSTAT service,
  108. Xwhich pipes the output from the WHO command to standard output.
  109. X
  110. XBy default, the front-end programs assume that the vendor-provided
  111. Xdaemons will be moved to the "/usr/etc/..." directory.  If you want
  112. Xsomething else, adjust the REAL_DAEMON and the REAL_DAEMON_DIR macros
  113. Xin the files miscd.c and tcpd.c.
  114. X
  115. XBy default, connections are logged to the same place where the sendmail
  116. Xlog entries go.  If connections should be logged elsewhere, adjust the
  117. XLOG_MAIL macro in the miscd.c and tcpd.c files, and update your inetd
  118. Xconfiguration file (usually, /etc/syslog.conf).  Most Ultrix versions 
  119. Xdo not provide this flexibility, though.
  120. X
  121. XBy default, the front-end programs support host access control.  Access
  122. Xcontrol is turned off when the /etc/hosts.{allow,deny} files do not
  123. Xexist. If you do not need support for host access control, adjust the
  124. Xmakefile so that the programs are compiled without -DHOSTS_ACCESS. Note:
  125. Xhost access control support requires the strchr() and strtok() routines.
  126. X
  127. XIf your C library does not provide the strcasecmp() routine, adjust the
  128. XAUX_OBJ macro in the makefile so that it uses the strcasecmp() version
  129. Xprovided with this package.
  130. X
  131. XThe tcpd program is intended for monitoring connections to the telnet,
  132. Xfinger, ftp, exec, rsh and rlogin services. Decide which services you
  133. Xwant to be monitored, move the vendor-provided daemon programs to the
  134. Xlocation specified by the REAL_DAEMON_DIR macro in the file tcpd.c, and
  135. Xcopy the tcpd front end to the locations where the vendor-provided
  136. Xdaemons used to be. That is, one copy of the tcpd front end for each
  137. Xservice that you want to monitor.
  138. X
  139. XUltrix only: if you want to monitor connections to the SYSTAT service,
  140. Xmove the vendor-provided miscd daemon to the location specified by the
  141. XREAL_DAEMON macro in the miscd.c file, and install the miscd front end
  142. Xinto the original miscd location.
  143. X
  144. XAcknowledgements:
  145. X
  146. XThanks to Brendan Kehoe (brendan@cs.widener.edu), Heimir Sverrisson
  147. X(heimir@hafro.is) and Dan Bernstein (brnstnd@kramden.acf.nyu.edu) for
  148. Xfeedback on an earlier release of this product.
  149. X
  150. X    Wietse Venema,
  151. X    Mathematics and Computing Science,
  152. X    Eindhoven University of Technology,
  153. X    The Netherlands.
  154. END_OF_README
  155. if test 4779 -ne `wc -c <README`; then
  156.     echo shar: \"README\" unpacked with wrong size!
  157. fi
  158. # end of overwriting check
  159. fi
  160. if test -f miscd.c -a "${1}" != "-c" ; then 
  161.   echo shar: Will not over-write existing file \"miscd.c\"
  162. else
  163. echo shar: Extracting \"miscd.c\" \(1709 characters\)
  164. sed "s/^X//" >miscd.c <<'END_OF_miscd.c'
  165. X /*
  166. X  * Front end to the ULTRIX miscd service. The front end logs the remote host
  167. X  * name and then invokes the real miscd daemon. Install as "/usr/etc/miscd",
  168. X  * after moving the real miscd daemon to the "/usr/etc/..." directory.
  169. X  * Connections and diagnostics are logged through syslog(3).
  170. X  * 
  171. X  * The Ultrix miscd program implements the systat service, which pipes the
  172. X  * output from who(1) to stdout. This information is potentially useful to
  173. X  * systems crackers.
  174. X  * 
  175. X  * Compile with -DHOSTS_ACCESS in order to enable access control. See the
  176. X  * hosts_access(5) manual page for details.
  177. X  * 
  178. X  * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  179. X  */
  180. X
  181. X#ifndef lint
  182. Xstatic char sccsid[] = "@(#) miscd.c 1.1 91/01/06 22:30:32";
  183. X#endif
  184. X
  185. X#include <stdio.h>
  186. X#include <syslog.h>
  187. X
  188. X/* The following specifies where the vendor-provided daemon should go. */
  189. X
  190. X#define REAL_DAEMON    "/usr/etc/.../miscd"
  191. X
  192. Xmain(argc, argv)
  193. Xint     argc;
  194. Xchar  **argv;
  195. X{
  196. X    char   *fromhost();
  197. X    char   *host_name;
  198. X
  199. X    /*
  200. X     * Open a channel to the syslog daemon. Older versions of openlog()
  201. X     * require only two arguments.
  202. X     */
  203. X
  204. X#ifdef LOG_MAIL
  205. X    (void) openlog(argv[0], LOG_PID, LOG_MAIL);
  206. X#else
  207. X    (void) openlog(argv[0], LOG_PID);
  208. X#endif
  209. X
  210. X    /* Find out and report the remote host name. */
  211. X
  212. X    if ((host_name = fromhost()) == 0)
  213. X    host_name = "unknown";
  214. X    syslog(LOG_INFO, "connect from %s", host_name);
  215. X
  216. X    /* Check whether this host can access the service in argv[0]. */
  217. X
  218. X#ifdef HOSTS_ACCESS
  219. X    hosts_access(argv[0], host_name);
  220. X#endif
  221. X
  222. X    /* Invoke the real daemon program. */
  223. X
  224. X    (void) execv(REAL_DAEMON, argv);
  225. X    syslog(LOG_ERR, "%s: %m", REAL_DAEMON);
  226. X    return (1);
  227. X}
  228. END_OF_miscd.c
  229. if test 1709 -ne `wc -c <miscd.c`; then
  230.     echo shar: \"miscd.c\" unpacked with wrong size!
  231. fi
  232. # end of overwriting check
  233. fi
  234. if test -f tcpd.c -a "${1}" != "-c" ; then 
  235.   echo shar: Will not over-write existing file \"tcpd.c\"
  236. else
  237. echo shar: Extracting \"tcpd.c\" \(1873 characters\)
  238. sed "s/^X//" >tcpd.c <<'END_OF_tcpd.c'
  239. X /*
  240. X  * General front end for connection-oriented tcp/ip services. This program
  241. X  * logs the remote host name and then invokes the real daemon. For example,
  242. X  * install as /usr/etc/{fingerd,telnetd,ftpd,rlogind,rshd,rexecd}, after
  243. X  * saving the real daemons in the directory "/usr/etc/...". This arrangement
  244. X  * requires that the network daemons are started by inetd or something
  245. X  * similar. Connections and diagnostics are logged through syslog(3).
  246. X  * 
  247. X  * Compile with -DHOSTS_ACCESS in order to enable access control. See the
  248. X  * hosts_access(5) manual page for details.
  249. X  * 
  250. X  * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  251. X  */
  252. X
  253. X#ifndef lint
  254. Xstatic char sccsid[] = "@(#) tcpd.c 1.1 91/01/06 22:30:36";
  255. X#endif
  256. X
  257. X#include <stdio.h>
  258. X#include <syslog.h>
  259. X#include <sys/types.h>
  260. X#include <sys/param.h>
  261. X#ifndef MAXPATHNAMELEN
  262. X#define MAXPATHNAMELEN    BUFSIZ
  263. X#endif
  264. X
  265. X/* The following specifies where the vendor-provided daemons should go. */
  266. X
  267. X#define REAL_DAEMON_DIR    "/usr/etc/..."
  268. X
  269. Xmain(argc, argv)
  270. Xint     argc;
  271. Xchar  **argv;
  272. X{
  273. X    char   *fromhost();
  274. X    char   *host_name;
  275. X    char    path[MAXPATHNAMELEN];
  276. X
  277. X    /*
  278. X     * Open a channel to the syslog daemon. Older versions of openlog()
  279. X     * require only two arguments.
  280. X     */
  281. X
  282. X#ifdef LOG_MAIL
  283. X    (void) openlog(argv[0], LOG_PID, LOG_MAIL);
  284. X#else
  285. X    (void) openlog(argv[0], LOG_PID);
  286. X#endif
  287. X
  288. X    /* Find out and report the remote host name. */
  289. X
  290. X    if ((host_name = fromhost()) == 0)
  291. X    host_name = "unknown";
  292. X    syslog(LOG_INFO, "connect from %s", host_name);
  293. X
  294. X    /* Check whether this host can access the service in argv[0]. */
  295. X
  296. X#ifdef HOSTS_ACCESS
  297. X    hosts_access(argv[0], host_name);
  298. X#endif
  299. X
  300. X    /* Invoke the real daemon program. */
  301. X
  302. X    (void) sprintf(path, "%s/%s", REAL_DAEMON_DIR, argv[0]);
  303. X    (void) execv(path, argv);
  304. X    syslog(LOG_ERR, "%s: %m", path);
  305. X    return (1);
  306. X}
  307. END_OF_tcpd.c
  308. if test 1873 -ne `wc -c <tcpd.c`; then
  309.     echo shar: \"tcpd.c\" unpacked with wrong size!
  310. fi
  311. # end of overwriting check
  312. fi
  313. if test -f fromhost.c -a "${1}" != "-c" ; then 
  314.   echo shar: Will not over-write existing file \"fromhost.c\"
  315. else
  316. echo shar: Extracting \"fromhost.c\" \(1325 characters\)
  317. sed "s/^X//" >fromhost.c <<'END_OF_fromhost.c'
  318. X /*
  319. X  * fromhost() returns the name or address of the host at the other end of
  320. X  * standard input, "stdin" if it is connected to a terminal, or a null
  321. X  * pointer if it fails. Diagnostics are logged through syslog(3).
  322. X  * 
  323. X  * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  324. X  */
  325. X
  326. X#ifndef lint
  327. Xstatic char sccsid[] = "@(#) fromhost.c 1.1 91/01/06 22:30:24";
  328. X#endif
  329. X
  330. X#include <stdio.h>
  331. X#include <sys/types.h>
  332. X#include <sys/param.h>
  333. X#include <sys/socket.h>
  334. X#include <syslog.h>
  335. X#include <netinet/in.h>
  336. X#include <netdb.h>
  337. X
  338. X/* fromhost - find out what is at the other end of standard input */
  339. X
  340. Xchar   *fromhost()
  341. X{
  342. X    struct sockaddr sa;
  343. X    struct sockaddr_in *sin = (struct sockaddr_in *) (&sa);
  344. X    struct hostent *hp;
  345. X    int     sockt = fileno(stdin);
  346. X    int     length = sizeof(sa);
  347. X    char   *inet_ntoa();
  348. X
  349. X    if (getpeername(sockt, &sa, &length) < 0) {
  350. X    if (isatty(sockt)) {
  351. X        return ("stdin");
  352. X    } else {
  353. X        syslog(LOG_ERR, "getpeername: %m");
  354. X        return (0);
  355. X    }
  356. X    } else {
  357. X    switch (sa.sa_family) {
  358. X    case AF_INET:
  359. X        hp = gethostbyaddr((char *) &sin->sin_addr.s_addr,
  360. X                   sizeof(sin->sin_addr.s_addr), AF_INET);
  361. X        return (hp ? hp->h_name : inet_ntoa(sin->sin_addr));
  362. X    default:
  363. X        syslog(LOG_ERR, "unknown address family %ld", sa.sa_family);
  364. X        return (0);
  365. X    }
  366. X    }
  367. X}
  368. END_OF_fromhost.c
  369. if test 1325 -ne `wc -c <fromhost.c`; then
  370.     echo shar: \"fromhost.c\" unpacked with wrong size!
  371. fi
  372. # end of overwriting check
  373. fi
  374. if test -f hosts_access.c -a "${1}" != "-c" ; then 
  375.   echo shar: Will not over-write existing file \"hosts_access.c\"
  376. else
  377. echo shar: Extracting \"hosts_access.c\" \(4055 characters\)
  378. sed "s/^X//" >hosts_access.c <<'END_OF_hosts_access.c'
  379. X#ifdef HOSTS_ACCESS
  380. X
  381. X /*
  382. X  * This module implements a simple but effective form of access control
  383. X  * based on host (or domain) names and service names, with wild card
  384. X  * support. Diagnostics are logged through syslog(3).
  385. X  * 
  386. X  * Compile with -DHOSTS_ACCESS in order to enable access control. See the
  387. X  * hosts_access(5) manual page for details.
  388. X  * 
  389. X  * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  390. X  */
  391. X
  392. X#ifndef lint
  393. Xstatic char sccsid[] = "@(#) hosts_access.c 1.1 91/01/06 22:30:28";
  394. X#endif
  395. X
  396. X#include <stdio.h>
  397. X#include <syslog.h>
  398. X
  399. Xextern char *fgets();
  400. Xextern char *strchr();
  401. Xextern char *strtok();
  402. Xextern void exit();
  403. X
  404. X /* Path names of the access control files. */
  405. X
  406. X#define HOSTS_ALLOW    "/etc/hosts.allow"
  407. X#define HOSTS_DENY    "/etc/hosts.deny"
  408. X
  409. X /* Delimiters for lists of services or hosts or domains. */
  410. X
  411. Xstatic char sep[] = ", \t";
  412. X
  413. X /* Constants to be used in assignments only, not in comparisons... */
  414. X
  415. X#define    YES        1
  416. X#define    NO        0
  417. X
  418. X/* hosts_access - host access control facility */
  419. X
  420. Xhosts_access(service, host)
  421. Xchar   *service;
  422. Xchar   *host;
  423. X{
  424. X
  425. X    /*
  426. X     * If the (service,host) pair is found in the /etc/hosts.allow file,
  427. X     * access is granted. Otherwise, if the (service,host) pair is found in
  428. X     * the /etc/hosts.deny file, access is denied. Otherwise, access is
  429. X     * granted. 
  430. X     * 
  431. X     * If a connection is refused, we write a syslog record, but do not notify
  432. X     * the client.
  433. X     */
  434. X
  435. X    if (table_match(HOSTS_ALLOW, service, host))
  436. X    return;
  437. X    if (table_match(HOSTS_DENY, service, host)) {
  438. X    syslog(LOG_WARNING, "refused connect from %s", host);
  439. X    exit(0);
  440. X    }
  441. X}
  442. X
  443. X/* table_match - match table entries with (service, host) pair */
  444. X
  445. Xtable_match(table, service, host)
  446. Xchar   *table;
  447. Xchar   *service;
  448. Xchar   *host;
  449. X{
  450. X    FILE   *fp;
  451. X    char    sv_list[BUFSIZ];        /* becomes list of services */
  452. X    char   *cl_list;            /* becomes list of clients */
  453. X    int     match = NO;
  454. X    int     end;
  455. X
  456. X    /*
  457. X     * Process the table one line at a time. Lines that begin with a '#'
  458. X     * character are ignored. Non-comment lines are broken at the ':'
  459. X     * character (we complain if there is none). The left part is matched
  460. X     * against the service name (argv[0]), the right part against the host
  461. X     * name. A non-existing table is treated as if it were an empty table.
  462. X     */
  463. X
  464. X    if (fp = fopen(table, "r")) {
  465. X    while (!match && fgets(sv_list, sizeof(sv_list), fp)) {
  466. X        if (sv_list[end = strlen(sv_list) - 1] != '\n') {
  467. X        syslog(LOG_ERR, "%s: line exceeds STDIO buffer size", table);
  468. X        } else {
  469. X        sv_list[end] = '\0';        /* strip trailing newline */
  470. X        }
  471. X        if (sv_list[0] == '#') {        /* skip comments */
  472. X        continue;
  473. X        } else if ((cl_list = strchr(sv_list, ':')) == 0) {
  474. X        syslog(LOG_ERR, "%s: malformed entry: \"%s\"", table, sv_list);
  475. X        continue;
  476. X        } else {
  477. X        *cl_list++ = '\0';        /* break line at ":" */
  478. X        match = (list_match(sv_list, service)
  479. X             && list_match(cl_list, host));
  480. X        }
  481. X    }
  482. X    (void) fclose(fp);
  483. X    }
  484. X    return (match);
  485. X}
  486. X
  487. X/* list_match - match a string against a list of tokens */
  488. X
  489. Xlist_match(list, string)
  490. Xchar   *list;
  491. Xchar   *string;
  492. X{
  493. X    char   *token;
  494. X    int     tok_len;
  495. X    int     str_len;
  496. X
  497. X    /*
  498. X     * Process tokens one at a time. If a token has the magic value "ALL" the
  499. X     * match always succeeds. If the token is a domain name, return YES if it
  500. X     * matches the last fields of the string. Otherwise, return YES if the
  501. X     * token fully matches the string. Note: we assume that a service name
  502. X     * never begins with a "." character.
  503. X     */
  504. X
  505. X    for (token = strtok(list, sep); token; token = strtok((char *) 0, sep)) {
  506. X    if (strcasecmp(token, "ALL") == 0) {    /* magic: always matches */
  507. X        return (YES);
  508. X    } else if (token[0] == '.') {        /* domain: match last fields */
  509. X        if ((str_len = strlen(string)) >= (tok_len = strlen(token))
  510. X        && strcasecmp(token, string + str_len - tok_len) == 0)
  511. X        return (YES);
  512. X    } else {                /* other: match full string */
  513. X        if (strcasecmp(token, string) == 0)
  514. X        return (YES);
  515. X    }
  516. X    }
  517. X    return (NO);
  518. X}
  519. X
  520. X#endif
  521. END_OF_hosts_access.c
  522. if test 4055 -ne `wc -c <hosts_access.c`; then
  523.     echo shar: \"hosts_access.c\" unpacked with wrong size!
  524. fi
  525. # end of overwriting check
  526. fi
  527. if test -f Makefile -a "${1}" != "-c" ; then 
  528.   echo shar: Will not over-write existing file \"Makefile\"
  529. else
  530. echo shar: Extracting \"Makefile\" \(1077 characters\)
  531. sed "s/^X//" >Makefile <<'END_OF_Makefile'
  532. X# @(#) Makefile 1.1 91/01/06 22:30:21
  533. X
  534. X## Begin configuration options
  535. X
  536. X# If you want to enable host access control, define the HOST_ACCESS macro
  537. X# in the  CFLAGS line. For example,
  538. X#
  539. X# CFLAGS = -O -DHOSTS_ACCESS
  540. X#
  541. X# Note: host access control requires the strtok() and strchr() routines.
  542. X
  543. XCFLAGS    = -O -DHOSTS_ACCESS
  544. X
  545. X# Include the file strcasecmp.o if it is not provided by your C library.
  546. X
  547. XAUX_OBJ    = # strcasecmp.o
  548. X
  549. X# Some System-V versions require that you explicitly specify the networking
  550. X# libraries.
  551. X
  552. XLIBS    =
  553. X
  554. X## End configuration options
  555. X
  556. XTCPD_OBJ= tcpd.o fromhost.o hosts_access.o
  557. XMISC_OBJ= miscd.o fromhost.o hosts_access.o
  558. X
  559. Xall:    tcpd miscd
  560. X
  561. Xtcpd:    $(TCPD_OBJ) $(AUX_OBJ)
  562. X    $(CC) $(CFLAGS) -o $@ $(TCPD_OBJ) $(AUX_OBJ) $(LIBS)
  563. X
  564. Xmiscd:    $(MISC_OBJ) $(AUX_OBJ)
  565. X    $(CC) $(CFLAGS) -o $@ $(MISC_OBJ) $(AUX_OBJ) $(LIBS)
  566. X
  567. Xshar:    
  568. X    @shar README miscd.c tcpd.c fromhost.c hosts_access.c Makefile \
  569. X    hosts_access.5 strcasecmp.c BLURB
  570. X
  571. Xclean:
  572. X    rm -f tcpd miscd *.o core
  573. X
  574. Xlint:
  575. X    lint -DHOSTS_ACCESS tcpd.c fromhost.c hosts_access.c
  576. X    lint -DHOSTS_ACCESS miscd.c fromhost.c hosts_access.c
  577. END_OF_Makefile
  578. if test 1077 -ne `wc -c <Makefile`; then
  579.     echo shar: \"Makefile\" unpacked with wrong size!
  580. fi
  581. # end of overwriting check
  582. fi
  583. if test -f hosts_access.5 -a "${1}" != "-c" ; then 
  584.   echo shar: Will not over-write existing file \"hosts_access.5\"
  585. else
  586. echo shar: Extracting \"hosts_access.5\" \(3088 characters\)
  587. sed "s/^X//" >hosts_access.5 <<'END_OF_hosts_access.5'
  588. X.TH HOSTS_ACCESS 5
  589. X.ad
  590. X.fi
  591. X.SH NAME
  592. Xhosts_access \- host access control files
  593. X.SH DESCRIPTION
  594. X.ad
  595. X.fi
  596. XThis manual page describes a simple, but effective, access control
  597. Xfacility that is based on host (or domain) names and service names,
  598. Xwith wild-card support.
  599. X.PP
  600. XIn the following text, \fIservice\fP is the name of a requested service
  601. X(the argv[0] value of a daemon process), and \fIhost\fP is the name of
  602. Xthe host requesting that service.
  603. X.IP o
  604. XAccess will be granted if the (service,host) pair is matched by an
  605. Xentry in the \fI/etc/hosts.allow\fP file.
  606. X.IP o
  607. XIf the previous test fails (perhaps because the \fIhosts.allow\fP file
  608. Xdoes not exist), access will be denied if the (service,host) pair is
  609. Xmatched by an entry in the \fI/etc/hosts.deny\fP file.
  610. X.IP o
  611. XIf the previous test fails (perhaps because the \fIhosts.deny\fP file
  612. Xdoes not exist), access will be granted.
  613. X.PP
  614. XA non-existing access control file is treated as if it were an empty
  615. Xfile. Thus, access control can be turned off by providing no access
  616. Xcontrol files.
  617. X.PP
  618. XThe format of the access control files is as follows.
  619. X.IP o
  620. XLines that begin with a `#' character are ignored.
  621. X.IP o
  622. XOther lines should have the format:
  623. X.sp
  624. X.ti +5
  625. Xservices : hosts_or_domains
  626. X.LP
  627. X\fIservices\fP is a list of one or more service names (argv[0] values),
  628. Xand \fIhosts_or_domains\fP is a list of one or more host or domain
  629. Xnames.  List elements are separated by blanks or commas.  The software
  630. Xdoes not distinguish between lower and upper case.
  631. X.PP
  632. XEntries that specify a domain name should begin with a `.' character
  633. X(see example below). A host name can be a fully-qualified host name,
  634. Xan undomained host name (no `.' characters) or an internet address.
  635. X.PP
  636. XSpecial meaning is given to the magic token \fIALL\fP.  If it appears
  637. Xin the \fIservices\fP part of a line, this token matches all services.
  638. XIf the magic token appears in the \fIhosts_or_domains\fP part of a
  639. Xline, it matches all hosts or domains.
  640. X.SH EXAMPLES
  641. XThe following example restricts all services to \fIhosta,
  642. Xhostb\fP and hosts below the \fI.some.domain\fP:
  643. X.PP
  644. X/etc/hosts.allow:
  645. X.in +5
  646. XALL: hosta, hostb, .some.domain
  647. X.PP
  648. X/etc/hosts.deny:
  649. X.in +5
  650. XALL: ALL
  651. X.PP
  652. XIn order to deny some hosts all services, except ftp:
  653. X.PP
  654. X/etc/hosts.allow:
  655. X.in +5
  656. Xin.ftpd: ALL
  657. X.PP
  658. X/etc/hosts.deny
  659. X.in +5
  660. XALL: some.host.name, .some.domain
  661. X.SH DIAGNOSTICS
  662. X.ad
  663. X.fi
  664. XA syslog record is produced when a connection is refused; when a syntax
  665. Xerror is found in a host access control file; when the length of a line
  666. Xin a host access control file exceeds the stdio(3) buffer size.
  667. X.SH FILES
  668. X.na
  669. X.nf
  670. X/etc/hosts.allow, (service,host) pairs that are granted access.
  671. X/etc/hosts.deny, (service,host) pairs that are denied access.
  672. X.SH BUGS
  673. X.ad
  674. X.fi
  675. XAuthorized hosts may be denied access if the mapping of host address
  676. Xto host name fails (for example, due to a problem in the name server).
  677. X.SH AUTHOR
  678. X.na
  679. X.nf
  680. XWietse Venema
  681. XEindhoven University of Technology
  682. XDepartment of Mathematics and Computer Science
  683. XDen Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  684. X\" @(#) hosts_access.5 1.1 91/01/06 22:30:26
  685. END_OF_hosts_access.5
  686. if test 3088 -ne `wc -c <hosts_access.5`; then
  687.     echo shar: \"hosts_access.5\" unpacked with wrong size!
  688. fi
  689. # end of overwriting check
  690. fi
  691. if test -f strcasecmp.c -a "${1}" != "-c" ; then 
  692.   echo shar: Will not over-write existing file \"strcasecmp.c\"
  693. else
  694. echo shar: Extracting \"strcasecmp.c\" \(3767 characters\)
  695. sed "s/^X//" >strcasecmp.c <<'END_OF_strcasecmp.c'
  696. X/*
  697. X * Copyright (c) 1987 Regents of the University of California.
  698. X * All rights reserved.
  699. X *
  700. X * Redistribution and use in source and binary forms are permitted
  701. X * provided that the above copyright notice and this paragraph are
  702. X * duplicated in all such forms and that any documentation,
  703. X * advertising materials, and other materials related to such
  704. X * distribution and use acknowledge that the software was developed
  705. X * by the University of California, Berkeley.  The name of the
  706. X * University may not be used to endorse or promote products derived
  707. X * from this software without specific prior written permission.
  708. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  709. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  710. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  711. X */
  712. X
  713. X#if defined(LIBC_SCCS) && !defined(lint)
  714. Xstatic char sccsid[] = "@(#)strcasecmp.c    5.6 (Berkeley) 6/27/88";
  715. X#endif /* LIBC_SCCS and not lint */
  716. X
  717. X#include <sys/types.h>
  718. X
  719. X/*
  720. X * This array is designed for mapping upper and lower case letter
  721. X * together for a case independent comparison.  The mappings are
  722. X * based upon ascii character sequences.
  723. X */
  724. Xstatic u_char charmap[] = {
  725. X    '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
  726. X    '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
  727. X    '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
  728. X    '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
  729. X    '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
  730. X    '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
  731. X    '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
  732. X    '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
  733. X    '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  734. X    '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  735. X    '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  736. X    '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
  737. X    '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  738. X    '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  739. X    '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  740. X    '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
  741. X    '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
  742. X    '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
  743. X    '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
  744. X    '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
  745. X    '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
  746. X    '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
  747. X    '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
  748. X    '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
  749. X    '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  750. X    '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  751. X    '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  752. X    '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337',
  753. X    '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  754. X    '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  755. X    '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  756. X    '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
  757. X};
  758. X
  759. Xstrcasecmp(s1, s2)
  760. X    char *s1, *s2;
  761. X{
  762. X    register u_char    *cm = charmap,
  763. X            *us1 = (u_char *)s1,
  764. X            *us2 = (u_char *)s2;
  765. X
  766. X    while (cm[*us1] == cm[*us2++])
  767. X        if (*us1++ == '\0')
  768. X            return(0);
  769. X    return(cm[*us1] - cm[*--us2]);
  770. X}
  771. X
  772. Xstrncasecmp(s1, s2, n)
  773. X    char *s1, *s2;
  774. X    register int n;
  775. X{
  776. X    register u_char    *cm = charmap,
  777. X            *us1 = (u_char *)s1,
  778. X            *us2 = (u_char *)s2;
  779. X
  780. X    while (--n >= 0 && cm[*us1] == cm[*us2++])
  781. X        if (*us1++ == '\0')
  782. X            return(0);
  783. X    return(n < 0 ? 0 : cm[*us1] - cm[*--us2]);
  784. X}
  785. END_OF_strcasecmp.c
  786. if test 3767 -ne `wc -c <strcasecmp.c`; then
  787.     echo shar: \"strcasecmp.c\" unpacked with wrong size!
  788. fi
  789. # end of overwriting check
  790. fi
  791. if test -f BLURB -a "${1}" != "-c" ; then 
  792.   echo shar: Will not over-write existing file \"BLURB\"
  793. else
  794. echo shar: Extracting \"BLURB\" \(1068 characters\)
  795. sed "s/^X//" >BLURB <<'END_OF_BLURB'
  796. X@(#) BLURB 1.1 91/01/06 22:30:19
  797. X
  798. XThis package provides a couple of tiny programs that log all requests
  799. Xto connection-oriented tcp/ip services (examples: FINGER, SYSTAT, FTP,
  800. XTELNET, RLOGIN, RSH, EXEC), with optional access control on the basis
  801. Xof host (or domain) names and service names.
  802. X
  803. XThe programs are nothing but small front ends. By default, they just
  804. Xlog the remote host name and then invoke the real daemon. The programs
  805. Xshould not require any changes to existing software or configuration
  806. Xfiles.
  807. X
  808. XConnections are reported through the syslog(3) facility. Each record
  809. Xcontains a time stamp, the remote host name and the name of the service
  810. Xrequested. Such information can be useful to detect break-in attempts
  811. Xor other undesirable activities, especially when logfile information
  812. Xfrom several hosts is merged.
  813. X
  814. XThe optional access-control facility may be useful when, for whatever
  815. Xreason, it is not possible to handle access control at a more suitable
  816. Xlevel (such as an internet router).
  817. X
  818. X    Wietse Venema,
  819. X    Eindhoven University of Technology,
  820. X    The Netherlands.
  821. END_OF_BLURB
  822. if test 1068 -ne `wc -c <BLURB`; then
  823.     echo shar: \"BLURB\" unpacked with wrong size!
  824. fi
  825. # end of overwriting check
  826. fi
  827. echo shar: End of shell archive.
  828. exit 0
  829.  
  830. exit 0 # Just in case...
  831. -- 
  832. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  833. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  834. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  835. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  836.